<template>
  <div class="app-container p-rel">
    <div class="container-title">查询</div>
    <form-edit class="p-abs" :detailForm="detailForm" :isEdit="isEdit" @submitForm="submitForm" :editVisible.sync="editVisible" v-if="editVisible"></form-edit>
    <el-form :model="queryParams" class="divForm"  ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="85px">
      <el-row :gutter="15">
        <el-col :lg="8" :xl="6">
          <el-form-item label="体检报告主键id" prop="personnelHeathId">
            <el-input
              v-model="queryParams.personnelHeathId"
              placeholder="请输入体检报告主键id"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="体检机构编号" prop="bhkOrganCode">
            <el-input
              v-model="queryParams.bhkOrganCode"
              placeholder="请输入体检机构编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="体检编号" prop="bhkCode">
            <el-input
              v-model="queryParams.bhkCode"
              placeholder="请输入体检编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="社会信用代码" prop="institutionCode">
            <el-input
              v-model="queryParams.institutionCode"
              placeholder="请输入社会信用代码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="所属地区编码" prop="zoneCode">
            <el-input
              v-model="queryParams.zoneCode"
              placeholder="请输入所属地区编码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="企业名称" prop="crptName">
            <el-input
              v-model="queryParams.crptName"
              placeholder="请输入企业名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="人员姓名" prop="personName">
            <el-input
              v-model="queryParams.personName"
              placeholder="请输入人员姓名"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="身份证号" prop="idc">
            <el-input
              v-model="queryParams.idc"
              placeholder="请输入身份证号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="出生日期" prop="brth">
            <el-input
              v-model="queryParams.brth"
              placeholder="请输入出生日期"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="年龄" prop="age">
            <el-input
              v-model="queryParams.age"
              placeholder="请输入年龄"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="婚否" prop="isxmrd">
            <el-input
              v-model="queryParams.isxmrd"
              placeholder="请输入婚否"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="人员联系电话" prop="lnkTel">
            <el-input
              v-model="queryParams.lnkTel"
              placeholder="请输入人员联系电话"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="体检人员工作部门" prop="dpt">
            <el-input
              v-model="queryParams.dpt"
              placeholder="请输入体检人员工作部门"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="人员工号" prop="wrkNum">
            <el-input
              v-model="queryParams.wrkNum"
              placeholder="请输入人员工号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="总工龄年数" prop="wrkLnt">
            <el-input
              v-model="queryParams.wrkLnt"
              placeholder="请输入总工龄年数"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="总工龄月数" prop="wrkLntMonth">
            <el-input
              v-model="queryParams.wrkLntMonth"
              placeholder="请输入总工龄月数"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="接害工龄年数" prop="tchBadRsnTim">
            <el-input
              v-model="queryParams.tchBadRsnTim"
              placeholder="请输入接害工龄年数"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="接害工龄月数" prop="tchBadRsnMonth">
            <el-input
              v-model="queryParams.tchBadRsnMonth"
              placeholder="请输入接害工龄月数"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="工种名称" prop="workName">
            <el-input
              v-model="queryParams.workName"
              placeholder="请输入工种名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="在岗状态编码" prop="onguardState">
            <el-input
              v-model="queryParams.onguardState"
              placeholder="请输入在岗状态编码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="体检日期" prop="bhkDate">
            <el-input
              v-model="queryParams.bhkDate"
              placeholder="请输入体检日期"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="体检结果" prop="bhkRst">
            <el-input
              v-model="queryParams.bhkRst"
              placeholder="请输入体检结果"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="主检建议" prop="mhkAdv">
            <el-input
              v-model="queryParams.mhkAdv"
              placeholder="请输入主检建议"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="体检结论" prop="verDict">
            <el-input
              v-model="queryParams.verDict"
              placeholder="请输入体检结论"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="主检医师工号" prop="mhkdctno">
            <el-input
              v-model="queryParams.mhkdctno"
              placeholder="请输入主检医师工号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="主检医师" prop="mhkDct">
            <el-input
              v-model="queryParams.mhkDct"
              placeholder="请输入主检医师"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="主检判定日期" prop="jdgdat">
            <el-input
              v-model="queryParams.jdgdat"
              placeholder="请输入主检判定日期"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="报告出具日期" prop="rptPrintDate">
            <el-input
              v-model="queryParams.rptPrintDate"
              placeholder="请输入报告出具日期"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="报告上传日" prop="createDate">
            <el-input
              v-model="queryParams.createDate"
              placeholder="请输入报告上传日"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="接害因素" prop="badRsn">
            <el-input
              v-model="queryParams.badRsn"
              placeholder="请输入接害因素"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="是否为复检 0：正常1：复检" prop="ifRhk">
            <el-input
              v-model="queryParams.ifRhk"
              placeholder="请输入是否为复检 0：正常1：复检"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="复检对应的上次体检编号" prop="lastBhkCode">
            <el-input
              v-model="queryParams.lastBhkCode"
              placeholder="请输入复检对应的上次体检编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
          <el-form-item label="其他危害因素" prop="otherBadrsn">
            <el-input
              v-model="queryParams.otherBadrsn"
              placeholder="请输入其他危害因素"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :lg="8" :xl="6">
            <el-button type="primary" icon="" size="" @click="handleQuery">搜索</el-button>
            <el-button icon="" size="" @click="resetQuery">重置</el-button>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['health:detail:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['health:detail:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['health:detail:remove']"
        >删除</el-button>
      </el-col>
      <!--<el-col :span="1.5">
       <el-button
          plain
          size="mini"
          @click="handleExport"
          v-hasPermi="['health:detail:export']"
        >导出</el-button>
      </el-col>-->
      <!--<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>

    <el-table v-loading="loading" :data="detailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="唯一标识" align="center" prop="uuid" />
      <el-table-column label="体检报告主键id" align="center" prop="personnelHeathId" />
      <el-table-column label="体检机构编号" align="center" prop="bhkOrganCode" />
      <el-table-column label="体检编号" align="center" prop="bhkCode" />
      <el-table-column label="社会信用代码" align="center" prop="institutionCode" />
      <el-table-column label="所属地区编码" align="center" prop="zoneCode" />
      <el-table-column label="企业名称" align="center" prop="crptName" />
      <el-table-column label="人员姓名" align="center" prop="personName" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="身份证号" align="center" prop="idc" />
      <el-table-column label="出生日期" align="center" prop="brth" />
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="婚否" align="center" prop="isxmrd" />
      <el-table-column label="人员联系电话" align="center" prop="lnkTel" />
      <el-table-column label="体检人员工作部门" align="center" prop="dpt" />
      <el-table-column label="人员工号" align="center" prop="wrkNum" />
      <el-table-column label="总工龄年数" align="center" prop="wrkLnt" />
      <el-table-column label="总工龄月数" align="center" prop="wrkLntMonth" />
      <el-table-column label="接害工龄年数" align="center" prop="tchBadRsnTim" />
      <el-table-column label="接害工龄月数" align="center" prop="tchBadRsnMonth" />
      <el-table-column label="工种名称" align="center" prop="workName" />
      <el-table-column label="在岗状态编码" align="center" prop="onguardState" />
      <el-table-column label="体检日期" align="center" prop="bhkDate" />
      <el-table-column label="体检结果" align="center" prop="bhkRst" />
      <el-table-column label="主检建议" align="center" prop="mhkAdv" />
      <el-table-column label="体检结论" align="center" prop="verDict" />
      <el-table-column label="主检医师工号" align="center" prop="mhkdctno" />
      <el-table-column label="主检医师" align="center" prop="mhkDct" />
      <el-table-column label="体检类型编码" align="center" prop="bhkType" />
      <el-table-column label="主检判定日期" align="center" prop="jdgdat" />
      <el-table-column label="报告出具日期" align="center" prop="rptPrintDate" />
      <el-table-column label="报告上传日" align="center" prop="createDate" />
      <el-table-column label="接害因素" align="center" prop="badRsn" />
      <el-table-column label="是否为复检 0：正常1：复检" align="center" prop="ifRhk" />
      <el-table-column label="复检对应的上次体检编号" align="center" prop="lastBhkCode" />
      <el-table-column label="人员类型  1：有身份证人员2：外籍人员3：无身份证人员" align="center" prop="psnType" />
      <el-table-column label="其他危害因素" align="center" prop="otherBadrsn" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row,2)"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row,1)"
            v-hasPermi="['health:detail:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['health:detail:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listDetail, getDetail, delDetail, addDetail, updateDetail } from "@/api/health/detail";
import formEdit from './editFrom.vue'
export default {
  name: "Detail",
  components:{ formEdit },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 体检详情表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        personnelHeathId: null,
        bhkOrganCode: null,
        bhkCode: null,
        institutionCode: null,
        zoneCode: null,
        crptName: null,
        personName: null,
        sex: null,
        idc: null,
        brth: null,
        age: null,
        isxmrd: null,
        lnkTel: null,
        dpt: null,
        wrkNum: null,
        wrkLnt: null,
        wrkLntMonth: null,
        tchBadRsnTim: null,
        tchBadRsnMonth: null,
        workName: null,
        onguardState: null,
        bhkDate: null,
        bhkRst: null,
        mhkAdv: null,
        verDict: null,
        mhkdctno: null,
        mhkDct: null,
        bhkType: null,
        jdgdat: null,
        rptPrintDate: null,
        createDate: null,
        badRsn: null,
        ifRhk: null,
        lastBhkCode: null,
        psnType: null,
        otherBadrsn: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      detailForm:{},
      isEdit:false,
      editVisible:false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询体检详情列表 */
    getList() {
      this.loading = true;
      listDetail(this.queryParams).then(response => {
        this.detailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        uuid: null,
        personnelHeathId: null,
        bhkOrganCode: null,
        bhkCode: null,
        institutionCode: null,
        zoneCode: null,
        crptName: null,
        personName: null,
        sex: null,
        idc: null,
        brth: null,
        age: null,
        isxmrd: null,
        lnkTel: null,
        dpt: null,
        wrkNum: null,
        wrkLnt: null,
        wrkLntMonth: null,
        tchBadRsnTim: null,
        tchBadRsnMonth: null,
        workName: null,
        onguardState: null,
        bhkDate: null,
        bhkRst: null,
        mhkAdv: null,
        verDict: null,
        mhkdctno: null,
        mhkDct: null,
        bhkType: null,
        jdgdat: null,
        rptPrintDate: null,
        createDate: null,
        badRsn: null,
        ifRhk: null,
        lastBhkCode: null,
        psnType: null,
        otherBadrsn: null,
        createBy: null,
        createTime: null,
        updateId: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.uuid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.detailForm = {}
      this.isEdit = false
      this.editVisible = true
    },
    /** 修改按钮操作 */
    handleUpdate(row,type) {
      // this.reset();
      const uuid = row.uuid || this.ids
      getDetail(uuid).then(response => {
        this.detailForm = response.data
        if(type == 1){
          this.isEdit = true
        }else{ // 查看
          this.isEdit = false
        }
        this.editVisible = true

      });
    },
    /** 提交按钮 */
    submitForm(form,id) {
    if (id != null) {
      updateDetail(form).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.editVisible = false;
        this.getList();
      });
    } else {
      addDetail(form).then(response => {
        this.$modal.msgSuccess("新增成功");
        this.editVisible = false;
        this.getList();
      });
    }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const uuids = row.uuid || this.ids;
      this.$modal.confirm('是否确认删除体检详情编号为"' + uuids + '"的数据项？').then(function() {
        return delDetail(uuids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('health/detail/export', {
        ...this.queryParams
      }, `detail_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
